#coding=utf-8
'''
Created on 2016 7 13

@author: 404158
'''
import sys
from common import check_detect_connected
sys.path.append('D:\eclipse\luyouqi\src')

import testcase.Dlink615.Login_Dlink_D615
import time
import ConfigParser
import common.logging_save
import common.machine_connect_wifi    #连接WIFI
import common.check_detect_connected   #检测WIFI是否连接成功
import unittest
import common.assertcheck
import shutil
import os
class Test(unittest.TestCase):
    def setUp(self):
        common.logging_save.logging.info("D-Link_D615路由器信道即将设为channel11通道......")
        print time.ctime(),"D-Link_D615路由器信道即将设为channel11通道......"
        self.Driver = testcase.Dlink615.Login_Dlink_D615.Login()
        self.Driver.implicitly_wait(10)
        self.Driver.find_element_by_xpath("/html/body/div[2]/table/tbody/tr/td/table[3]/tbody/tr/td[1]/div/ul[1]/li[3]/div/a").click()
        time.sleep(2)
        self.Driver.find_element_by_id("ManualWirelessSetup").click()  #点击：手动无线因特网安装
        time.sleep(2)

        self.Driver.find_element_by_xpath("//select[@id='channel_1']//option[@value='11']").click()  #设置通道
        
        time.sleep(3)

        self.Driver.find_element_by_id("SaveSettings_Btm").click()
        time.sleep(2)
        self.Driver.find_element_by_id("RestartNow").click()
        time.sleep(100)          #需要save 40秒时间

        common.logging_save.logging.info("D-Link_D615路由器密信道已经设为channel11通道")
        print time.ctime(),"D-Link_D615路由器信道已经设为channel11通道......"
        self.Driver.quit()
        
    def tearDown(self):
        sys.path.append('\report')
        basic_path = common.config.save_report()
        different = os.path.join(common.config.save_report(),'Dlink615','channel11.txt')
        shutil.copyfile(check_detect_connected.save_path,different)
        #self.Driver.quit()

    def testName(self):    #进行连接操作，然后进行判断是否连接成功，如失败则报错
        u"""测试步骤：设置通道为channel11，然后WIFI设备连接路由器   期待结果：可以连接成功，如果连接失败，则直接报错"""

        self.assertEqual('success', common.assertcheck.Test(), "经过检测未连接成功，请排查问题所在")

        common.logging_save.logging.info("检测完毕，可以正常连接WIFI")
        print time.ctime(),"检测完毕，可以正常连接WIFI"
   
if __name__ == "__main__":
    unittest.main()
    
    